package com.jbl.te.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jbl.te.entity.Course;
import com.jbl.te.entity.vo.CourseQuery;
import com.jbl.te.mapper.CourseMapper;
import com.jbl.te.service.CourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jbl
 * @since 2020-12-11
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Override
    public void pageQuery(Page<Course> pageParam, CourseQuery courseQuery) {
        if (courseQuery == null) {
            this.page(pageParam,null);
            return;
        }
        String name = courseQuery.getName();
        Integer courseType=courseQuery.getCourseType();
        String collegeId = courseQuery.getCollegeId();
        QueryWrapper<Course> wrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(name)) {
            wrapper.like("name",name);
        }
        if (!StringUtils.isEmpty(courseType))
        {
            wrapper.eq("course_type",courseType);
        }
        if(!StringUtils.isEmpty(collegeId)) {
            wrapper.eq("college_id",collegeId);
        }
        this.page(pageParam,wrapper);
    }
}
